/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Combo.java
 *
 * Created on 3 Ιουν 2010, 9:40:09 πμ
 */

package testvalidators;

import com.googlecode.svalidators.formcomponents.ValidationGroup;
import com.googlecode.svalidators.validators.NumericValidator;
import com.googlecode.svalidators.validators.RangeValidator;
import com.googlecode.svalidators.validators.RequiredValidator;

/**
 *
 * @author ssoldatos
 */
public class Combo extends javax.swing.JPanel {

    /** Creates new form Combo */
    public Combo() {
        initComponents();
        combo_required.setAllowEmpty(false);
        combo_range.addValidator(new RangeValidator("", 10, 100, true));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    combo_required = new com.googlecode.svalidators.formcomponents.SComboBox();
    button = new javax.swing.JButton();
    jLabel2 = new javax.swing.JLabel();
    combo_numeric = new com.googlecode.svalidators.formcomponents.SComboBox(new NumericValidator());
    jLabel3 = new javax.swing.JLabel();
    combo_range = new com.googlecode.svalidators.formcomponents.SComboBox();
    jLabel4 = new javax.swing.JLabel();

    setBackground(new java.awt.Color(255, 255, 255));
    setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel1.setText("Required :");

    combo_required.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Choose an item", "Item 1", "Item 2", "Item 3", "Item 4" }));
    combo_required.setName("Required"); // NOI18N

    button.setText("Validate");
    button.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        buttonActionPerformed(evt);
      }
    });

    jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel2.setText("Numeric not empty  :");

    combo_numeric.setEditable(true);
    combo_numeric.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "10", "20", "30", "40", "50" }));
    combo_numeric.setName("Numeric"); // NOI18N

    jLabel3.setText("Range allow empty :");

    combo_range.setEditable(true);
    combo_range.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "10", "50", "100" }));
    combo_range.setName("Range"); // NOI18N

    jLabel4.setText("Value 10 -100");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
              .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
              .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
              .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(combo_required, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                  .addComponent(combo_numeric, 0, 0, Short.MAX_VALUE))
                .addGap(130, 130, 130))
              .addGroup(layout.createSequentialGroup()
                .addComponent(combo_range, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addGap(52, 52, 52)))
            .addGap(66, 66, 66))
          .addGroup(layout.createSequentialGroup()
            .addGap(10, 10, 10)
            .addComponent(button)))
        .addContainerGap())
    );

    layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {combo_numeric, combo_range, combo_required});

    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGap(28, 28, 28)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel1)
          .addComponent(combo_required, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel2)
          .addComponent(combo_numeric, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel3)
          .addComponent(combo_range, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel4))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
        .addComponent(button)
        .addContainerGap())
    );
  }// </editor-fold>//GEN-END:initComponents

    private void buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonActionPerformed
      ValidationGroup group = new ValidationGroup();
      group.addComponent(combo_required);
      group.addComponent(combo_numeric);
      group.addComponent(combo_range);
      if(!group.validate()){
        group.errorMessage(true);
      }
    }//GEN-LAST:event_buttonActionPerformed


  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton button;
  private com.googlecode.svalidators.formcomponents.SComboBox combo_numeric;
  private com.googlecode.svalidators.formcomponents.SComboBox combo_range;
  private com.googlecode.svalidators.formcomponents.SComboBox combo_required;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  // End of variables declaration//GEN-END:variables

}
